<?php

namespace app\common\service;


use Curl\Curl;

abstract class service
{
    protected $curl;

    public function __construct()
    {
        $this->curl = new Curl();
        $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
        $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, false);
    }

    abstract function makeSign();

    abstract public function getParams();

    public function get($url)
    {
        $this->curl->get($url, $this->getParams());
    }

    public function post($url, $asJson = false)
    {
        $this->curl->post($url, $this->getParams(), $asJson);
    }

    public function close()
    {
        $this->curl->close();
    }

    public function error()
    {
        return $this->curl->error_message;
    }

    public function errorCode()
    {
        return $this->curl->error_code;
    }
    /**
     * Get the decoded body of the response.
     *
     * @return array
     */
    public function payload()
    {
        return json_decode($this->curl->response, true);
    }

    public function sortKey()
    {
        $args = $this->getParams();
        if (isset($args['sign']))
            unset($args['sign']);
        ksort($args);
        return $args;
    }
}